package com.lc.qianrenshiye.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.conn.GoodsTypeGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/11/25.
 */
public class HomeTabAdapter extends ArrayAdapter<GoodsTypeGet.GoodsType> {

    private Context context;
    private List<GoodsTypeGet.GoodsType> tabLists;
    private LayoutInflater layoutInflater;
    public int selPosition;

    public HomeTabAdapter(Context context, List<GoodsTypeGet.GoodsType> tabLists) {
        super(context, 0, tabLists);

        this.context = context;
        this.tabLists = tabLists;
        layoutInflater = LayoutInflater.from(context);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        GoodsTypeGet.GoodsType goodsType = getItem(position);

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_home_tab, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        if (selPosition == position) {

            viewHolder.item_tab_tv.setTextColor(ContextCompat.getColor(context, R.color.red_color));

        } else {

            viewHolder.item_tab_tv.setTextColor(ContextCompat.getColor(context, R.color.black_text_color));

        }

        viewHolder.item_tab_tv.setText(goodsType.title);

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.item_tab_tv) private TextView item_tab_tv;
    }
}
